package com.example.template.ui.home.state;

import androidx.databinding.ObservableField;

import com.example.base.http.ApiObserver;
import com.example.base.http.HttpClient;
import com.example.base.http.ResponseData;
import com.example.base.ui.BaseViewModel;
import com.example.template.http.entity.NoticeEntity;
import com.example.template.http.service.HomeApiService;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class HomeVewModel extends BaseViewModel {
    public ObservableField<NoticeEntity> result = new ObservableField<>();

    public void requestApi(){
        HttpClient.getInstance().create(HomeApiService.class)
                .getNotice("cms_notice")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())//回调到主线程
                .subscribe(new ApiObserver<ResponseData<List<NoticeEntity>>>() {
                    @Override
                    public void onResult(ResponseData<List<NoticeEntity>> listResponseData) {
                        result.set(listResponseData.getResult().get(0));
                    }
                });
    }
}
